﻿using Frame.Core.IServices.Admin;
using Frame.Core.Models;
using Frame.Core.Repository;
using System.Threading.Tasks;
using System.Linq;
using Frame.Core.Common.Attributes;

namespace Frame.Core.Services.Admin
{
    public class RolePowerService : BaseService<RolePowers>, IRolePowerService
    {
        readonly IRepositoryBase<RolePowers> _dal;


        public RolePowerService(IRepositoryBase<RolePowers> dal)
        {
            this._dal = dal;
            base.BaseDal = dal;
        }

        [Transaction]
        public async Task SaveRolePowerAsync(int roleID, int[] powers)
        {
            await _dal.DeleteAsync(d=>d.RoleID== roleID);
            if (powers.Length > 0)
            {
                var list = powers.Select(a => new RolePowers { RoleID = roleID, PowerID = a }).ToArray();
                await _dal.InsertAsync(list);
            }
        }
    }
}
